package com.wz.device.controller;


import com.wz.device.entity.BasDevice;
import com.wz.device.service.BasDeviceService;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qiqi
 * @since 2021-10-22
 */
@Controller
@RequestMapping("/device/basDevice")
public class BasDeviceController extends BaseController {

    private String prefix = "device/basDevice";

    @Autowired
    private BasDeviceService basDeviceService;



//    @RequiresPermissions("device:basDevice:view")
    @GetMapping()
    public String user() {
        return prefix + "/basDevice";
    }

    /**
     * 设备信息列表
     * @param basDevice
     * @return
     */
//    @RequiresPermissions("device:basDevice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BasDevice basDevice){
        startPage();
        List<BasDevice> list = basDeviceService.selectBasDeviceList(basDevice);
        return getDataTable(list);
    }


    /**
     * 新增设备信息
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        return prefix + "/add";
    }

    /**
     * 设备增加
     * @param basDevice
     * @return
     */
    @RequiresPermissions("device:basDevice:add")
    @Log(title = "设备管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated BasDevice basDevice)
    {
        return toAjax(basDeviceService.insertBasDevice(basDevice));
    }

    /**
     * 修改设备信息
     */
    @RequiresPermissions("device:basDevice:edit")
    @GetMapping("/edit/{device_id}")
    public String edit(@PathVariable("device_id") String device_id, ModelMap mmap)
    {
        mmap.put("device", basDeviceService.selectBasDevice(device_id));
        return prefix + "/edit";
    }

    /**
     * 修改保存设备信息
     */
    @RequiresPermissions("device:basDevice:edit")
    @Log(title = "设备管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated BasDevice basDevice)
    {
        return toAjax(basDeviceService.updateBasDevice(basDevice));

    }


    @RequiresPermissions("device:basDevice:remove")
    @Log(title = "设备管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(basDeviceService.deleteDeviceByIds(ids));
    }

    /**
     * 设备库房是否锁定修改
     */
    @Log(title = "设备管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("device:basDevice:edit")
    @PostMapping("/changeLocked")
    @ResponseBody
    public AjaxResult changeLocked(BasDevice basDevice)
    {
        return toAjax(basDeviceService.changeLocked(basDevice));
    }


}
